package com.atguigu.oss.utils;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 访问配置类中属性值的工具类
 */
@Component
public class ConstantPropertiesUtils implements InitializingBean {
    //在@Value()里面团如${xxxx.xxx}表达式,就是把配置文件中xxxx.xxx的属性值注入到注解的变量上
    @Value("${aliyun.oss.file.endpoint}")
    private String endPoint;
    @Value("${aliyun.oss.file.keyid}")
    private String keyId;
    @Value("${aliyun.oss.file.keysecret}")
    private String keySecret;
    @Value("${aliyun.oss.file.bucketname}")
    private String bucketName;

    //公开变量,让外部能访问到内部的私有变量
    public static String END_POINT;
    public static String ACCESS_KEY_ID;
    public static String ACCESS_KEY_SECRET;
    public static String BUCKET_NAME;
    @Override
    public void afterPropertiesSet() throws Exception {
        //实现接口InitializingBean所需要实现的方法.次方法就是在初始化Spring容器中Bean对象的时候调用
        //当上方Bean对象注入完成后,我们把里面的值复制给公开变量,来让外部访问
        END_POINT = endPoint;
        ACCESS_KEY_ID = keyId;
        ACCESS_KEY_SECRET = keySecret;
        BUCKET_NAME = bucketName;
    }
}
